import { ResDetail, ResPage } from './interface'
import request from '/@/utils/request'
type ContentType = 'json' | 'form' | 'multipart'
export const postService = <T>(url: string, data: any, type: ContentType = 'json'): Promise<ResDetail<T>> => {
  let headers = {}
  let body = data
  switch (type) {
    case 'json':
      headers = { 'Content-Type': 'application/json;charset=UTF-8' }
      body = JSON.stringify(data)
      break
    case 'form':
      headers = { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }
      body = data // 注意需要 import qs from 'qs'
      break
    case 'multipart':
      headers = { 'Content-Type': 'multipart/form-data' }
      // axios 会自动处理 FormData
      break
  }
  return request({
    url,
    method: 'post',
    data: body,
    headers,
  })
}
export const postServiceList = <T>(url: string, data: any, isJson: boolean): Promise<ResDetail<ResPage<T>>> => {
  return request({
    url,
    method: 'post',
    data,
    headers: { 'Content-Type': isJson ? 'application/json;charset=UTF-8' : 'multipart/form-data' },
  })
}
